#include "processVRML.h"
#include <vector>
#include <Eigenvalues>

#include "Point.h"

using namespace std;
using namespace Eigen;

VRMLmodel::VRMLmodel(char* fname) {
	printf("%s\n",fname);
	fp = fopen(fname,"w");
}

void VRMLmodel::initVRML(){
	fprintf(fp,"#VRML V1.0 ascii\n");
	fprintf(fp,"PointLight{ intensity 1 location 50 100 300 }\n");
	fprintf(fp,"PointLight{ intensity 1 location 40 100 250 }\n");
	fprintf(fp,"PointLight{ intensity 1 location 60 100 250 }\n");
	fprintf(fp,"PointLight{ intensity 1 location 20 100 100 }\n");
	fprintf(fp,"PointLight{ intensity 3 location 80 100 100 }\n");
	fprintf(fp,"PointLight{ intensity 5 location 50 400 50 }\n");
	fprintf(fp,"ShapeHints { \n");
	fprintf(fp," vertexOrdering  COUNTERCLOCKWISE \n");
	fprintf(fp," shapeType       SOLID \n");
	fprintf(fp," }\n");
	fprintf(fp,"Separator { \n");
}

void VRMLmodel::addPolygon(int i,Vector3i coordinates[4]) {
	printf("inside add polygon\n");
	fprintf(fp,"\n");
	fprintf(fp,"Separator {\n");
	fprintf(fp,"Coordinate3 { point [\n");
	for (int i = 0; i < 4; ++i) {
			fprintf(fp,"\t%d %d %d ,\n",
				int(coordinates[i](0)),int(coordinates[i](1)),int(coordinates[i](2)));
	}
	fprintf(fp,"]}\n");
	fprintf(fp,"Texture2 { filename \"patch%d.jpg\" }\n",i);
	fprintf(fp,"TextureCoordinate2 { point [\n");
	fprintf(fp,"0 1 ,\n");
	fprintf(fp,"0 0 ,\n");
	fprintf(fp,"1 0 ,\n");
	fprintf(fp,"1 1 ,\n");
	fprintf(fp,"]}\n");
	fprintf(fp,"IndexedFaceSet { coordIndex [0, 1, 2, 3]}\n");
	fprintf(fp,"}\n");
}

void VRMLmodel::closeVRML() {
	fprintf(fp,"}\n");
	fclose(fp);
}